// TOWN SCRIPT
//    Town 12: Henner's House
//    NOTE: Begger in Cresent Harbor is Henner...
//     (chance of talking if gave coins to him...)

// This is the special encounter script for this town.
// The states INIT_STATE, EXIT_STATE, and START_STATE have
// meanings that are described in the documenation. States you write
// yourself should be numbered from 10-100.

// flags:
// 12, 0 = Henner will talk to you...
// 12, 1 = front door sdf
// 12, 2 = trap sdf
// 12, 5 = talked to Henner in Cresent Harbor

begintownscript;

variables;

short i, ext, choice;

body;

beginstate INIT_STATE;
	set_crime_tolerance(3);
	turn_off_training(1);

	set_name(6, "Henner");
	set_char_dialogue_pic(6, 539, 0);

	// if you can't talk to him, determine if he will now...
	if (get_flag(12, 0) == 0) {
		if (get_flag(2, 19) > 0) {
			set_flag(12, 0, 1);
		}
		else {
			if (get_flag(2, 15) > 0) {
				// gave henner coins, have a chance to talk to him...
				i = get_ran(1, 1, 9);
				if (i <= get_flag(2, 15)) {
					// ok - he'll talk to you...
					// erase him from Cresent Harbor
					set_flag(2, 15, 10);
					set_flag(12, 0, 1);
				}
			}
		}
	}
break;

beginstate EXIT_STATE;
// Always called when the town is left.
break;

beginstate START_STATE;
	if (get_ran(1, 0, 100) < 6) {
		text_bubble_on_char(7, "Cluck Cluck");
	}
	if (get_ran(1, 0, 100) < 6) {
		text_bubble_on_char(8, "Cock-a-doodle-doo");
	}
	if (get_ran(1, 0, 100) < 6) {
		text_bubble_on_char(9, "Cluck Cluck");
	}
	if (get_ran(1, 0, 100) < 6) {
		text_bubble_on_char(10, "Mooo");
	}
	if (get_ran(1, 0, 100) < 6) {
		text_bubble_on_char(11, "Moooo");
	}
	if (get_ran(1, 0, 100) < 6) {
		text_bubble_on_char(12, "Baaaa");
	}
	if (get_ran(1, 0, 100) < 6) {
		if (get_ran(1, 1, 100) <= 50)
			text_bubble_on_char(13, "Woof");
		else
			text_bubble_on_char(13, "Howwwl");
	}
	if (get_ran(1, 0, 100) < 6) {
		if (get_ran(1, 1, 100) <= 50)
			text_bubble_on_char(14, "Meow");
		else
			text_bubble_on_char(14, "Purrrr");
	}
break;

beginstate 10;
	ext = 0;
	set_state_continue(12);
break;

beginstate 11;
	ext = 1;
	if (get_flag(12, 3) == 0) {
		// check to see if party notices 'fake' bookshelf...
		if (get_highest_skill(24) >= (get_ran(1, 1, 5) + 5)) {
			set_flag(12, 3, 1);
		}
	}
	set_state_continue(12);
break;

beginstate 12;
	reset_dialog();
	add_dialog_str(0, "The bookshelves are over-flowing with books.", 0);
	add_dialog_str(1, "The books cover all subjects including some on devils, demons and underworld creatures.", 0);
	add_dialog_str(2, "Unfortunately, the books cannot be looked at because of some sort of spell cast on them.", 0);
	if ((ext == 1) && (get_flag(12, 3) > 0)) {
		add_dialog_str(3, "You notice something funny about this bookshelf - it doesn't seem real!", 0);
	}
	add_dialog_choice(0, "OK");
	choice = run_dialog(1);
break;

beginstate 13;
	block_entry(1);
	if (get_flag(12, 4) > 0) {
		set_state_continue(14);
	}
	else {
		message_dialog("There is a portal here, but it doesn't seem to be active.", "What it's destination is, is anybodies guess.");
	}
break;

beginstate 14;
	reset_dialog_preset_options(3);
	choice = run_dialog(1);
	if (choice == 2) {
		play_sound(10);
		move_to_new_town(14, 24, 27);
	}
break;

beginstate 15;
	if (char_ok(6))
		set_state_continue(16);
	else
		set_state_continue(17);
break;

beginstate 16;
	message_dialog("The lever doesn't seem to do anything.", "Perhaps you should speak to Henner?");
break;

beginstate 17;
	if (get_flag(12, 4) == 0) {
		message_dialog("You inspect the lever closely and figure out how the lever works.", "As you pull the lever, you hear the portal outside become active.");
		set_flag(12, 4, 1);
	}
	else {
		message_dialog("You pull on the lever, but nothing else happens.", "The portal outside continues to hum in an active state.");
	}
break;

beginstate 18;
	if (get_flag(12, 4) > 0)
		message_dialog("The portal here seems to be active.", "Perhaps you should step into it.");
	else
		message_dialog("The portal here seems to not be active.", "");
break;
